import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtCharts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    ChartView {
        id: chartView
        title: "动画示例"
        titleFont.bold: true
        titleFont.pointSize: 14

        anchors.fill: parent
        antialiasing: true
        anchors.margins: 25

        animationDuration: 500
        // 此处设置会报错：Unable to assign int to QEasingCurve
        // animationEasingCurve: Easing.Linear
        // 应该是：
        animationEasingCurve.type: Easing.OutElastic
        animationEasingCurve.amplitude: 1.0
        animationEasingCurve.period: 0.3
        animationOptions: ChartView.SeriesAnimations

        BarCategoryAxis {
            id: valueAxisX
            categories: ["一月", "二月", "三月", "四月"]
            titleText: "X Title"
        }

        ValueAxis {
            id: valueAxisY
            min: 0
            max: 20
            titleText: "Y Title"
        }

        BarSeries {
            name: "柱形图分类坐标轴示例"
            axisX: valueAxisX
            axisY: valueAxisY

            BarSet {
                id: barSet
                label: "bar"
                values: [10, 15, 12, 18]
            }
        }
    }

    Row {
        Text {
            text: "请选择类型："
        }
        ComboBox {
            model: ListModel {
                id: model
                ListElement { text: "NoAnimationAnimation" }
                ListElement { text: "GridAxisAnimations" }
                ListElement { text: "SeriesAnimations" }
                ListElement { text: "AllAnimations" }
            }
            onActivated: {
                chartView.animationOptions = currentIndex
                // 改变柱形图的值， 触发SeriesAnimations动画效果
                barSet.values[0] = currentIndex + 2
            }
        }
    }
}
